/*
 * <p>Copyright® 2009-2022 东软 IT 实训中心版权所有。</p>
 */

package com.max.back.doctor.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.max.back.entity.PrescriptionItem;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

/**
* @description 
* 
* <p>
* <code>PrescriptionItemDao</code>
*
* </p>
* 
* @see 
* @author 辛凤文 forward.seen@foxmail.com
* @version 1.0 
* @time 2022/7/27 22:42 
*/
@Repository("/doctorPrescriptionItemDao")
public interface PrescriptionItemDao extends BaseMapper<PrescriptionItem> {

    /**
     * 根据
     * @return
     */
    Boolean deleteAndCreatePrescriptionItems();


    /**
     * 根据prescriptionId查询已存入库中的处方单项信息
     * @param prescriptionId
     * @return
     */
    @Select({
            "SELECT\n" +
                    "\td.id id,\n" +
                    "\td.name name,\n" +
                    "\td.specification specification,\n" +
                    "\td.manufacturer manufacturer,\n" +
                    "\td.usage_Dosage usageDosage,\n" +
                    "\td.drug_type drugType,\n" +
                    "\td.inventory inventory,\n" +
                    "\tp.drug_Amount drugAmount\n" +
                    "FROM\n" +
                    "\tPRESCRIPTION_ITEM p,\n" +
                    "\tDRUG d\n" +
                    "WHERE\n" +
                    "\td.DELETED = 0\n" +
                    "\tAND\n" +
                    "\tp.DELETED = 0\n" +
                    "\tAND\n" +
                    "\tp.PRESCRIPTION_ID = #{prescriptionId}\n" +
                    "\tAND\n" +
                    "\tp.DRUG_ID = d.ID"
    })
    List<Map<String, Object>> queryItemsByPrescriptionId(@Param("prescriptionId") String prescriptionId);
}